﻿package model.drawPanel.entitys;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wb.swt.SWTResourceManager;


public class Circle extends Entity {
	
/**
	 * 
	 */
	private static final long serialVersionUID = 101250103L;
private int fillColor = -1;

public Circle(int id, Color color, int width, int style, int x1, int y1,
			int x2, int y2) {
		super(id, color, width, style, x1, y1, x2, y2);
		// TODO Auto-generated constructor stub
	}
	
	public void setFillColor(int color){ 
		fillColor = color;
	}
	public void draw(Display display , GC gc) {
		if(color ==null){
			super.initeColor();
		}
		if(isChoosed){
			gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
			
			gc.setLineWidth(3);
			gc.setLineStyle(SWT.LINE_SOLID);
			gc.drawOval(x1-6, y1-6, 12, 12);
			gc.drawOval(x2-6, y1-6, 12, 12);
			gc.drawOval(x1-6, y2-6,	12, 12);
			gc.drawOval(x2-6, y2-6, 12, 12);
			gc.setForeground(color);
			gc.setLineStyle(style);
			gc.setLineWidth(width);
			gc.setAlpha(128);
			gc.drawOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1- y2));
			if(fillColor != -1){
				gc.fillOval(x1, y1, Math.abs(x1 - x2), Math.abs(y1- y2));
				
			}
			gc.setAlpha(255);
		}else{
			gc.setForeground(color);
			gc.setLineStyle(style);
			gc.setLineWidth(width);
			gc.drawOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1- y2));
			if(fillColor != -1){
				gc.fillOval(x1, y1, Math.abs(x1 - x2), Math.abs(y1- y2));
			
			}
		}
		
	}
	private int pointIsContained(double x,double y,double x1,double y1,double x2,double y2){
		double a = x2-x1;
		double b = y2-y1;
		double c = Math.sqrt(a*a-b*b);
		double length = super.distance(x, y, x1+a-c,y1) + super.distance(x, y, x1+a+c, y1);

		if(length < 2*a ){
			return -1;
		}
		if(length ==x*a){
			return 0;
		}
		else{//> 2*a
			return 1;
		}
		
	}
	public String isFocused(int x, int y){
		super.isFocused(x, y);
		if(isChoosed){
			if(distance(x1,y1,x,y) <= 6){
				return "zoomleftup";
			}
			if(distance(x1,y2,x,y) <= 6){
				return"zoomleftdown";
			}
			if(distance(x2,y1,x,y) <= 6 ){
				return"zoomrightup";
			}
			if(distance(x2,y2,x,y) <= 6){
				return"zoomrightdown";
			}
		}
		if(pointIsContained((double)x,(double) y, x1+width/2.0, (y1+y2)/2.0, (x2+x1)/2.0,y1+width/2.0)>=0 
		&& pointIsContained((double)x, (double)y, x1-width/2.0, (y1+y2)/2.0, (x2+x1)/2.0, y1-width/2.0) <=0){
			System.out.println("enter");
			return "entity";
		}
		return "noEnter";
	}
	

}